﻿<?php
/**
 * 竞赛详细界面
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');
require_once('Pager.php');


$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$request=$_GET;
if( empty( $request['no']) ){
	header('Location:../manager/manager_login.php');
}else{
	$no = $request['no'];
}
try{
 $db = db_connect();
 $contest = new contest_process( $db ) ;
 $contest->load( 'contest_no' , $no ); 

//@todo 是传入整个数组 由模板判断如何显示 还是传入单独的值?
//可以由db_obj.class提供一个get_all()方法返回所有的值
$contest_no = $no ;
$name = $contest->get('name');
$sign_begin_time = $contest->get('sign_begin_time');
$sign_end_time = $contest->get('sign_end_time');
$begin_time = $contest->get('begin_time');
$end_time = $contest->get('end_time');
$addtime = $contest->get('addtime');
$summary=$contest->get('summary');
$status=$contest->get('status'); 
$tpl->assign( 'contest_no' , $contest_no );
$tpl->assign( 'name' , $name );
$tpl->assign( 'sign_begin_time' , $sign_begin_time );
$tpl->assign( 'sign_end_time' , $sign_end_time );
$tpl->assign( 'begin_time' ,$begin_time );
$tpl->assign( 'end_time' , $end_time );
$tpl->assign( 'addtime' , $addtime );
$tpl->assign('summary',str_replace("\n","<br>",$summary));
$tpl->assign( 'status' , $status );


$problems=contest_problem_process::get_all($db,$contest_no);
if ( empty($problems) ){
		$isnotempty=false;		
		
}
else{
//动态获得结果数组的键名
	$titles = array_keys( $problems[0] );
	$problem_num = count( $problems );

	//此配置应该可以由配置文件读出
	$params = array(
    		'itemData' => $problems,
    		'perPage' => 30,
    		'delta' => 8,
    		'append' => true,
    		'clearIfVoid' => false,
    		'urlVar' => 'entrant',
    		'useSessions' => true,
    		'closeSession' => true,
    		'mode'  => 'Jumping',
	);
    $isnotempty=true;
	$pager = & Pager::factory($params);
	$page_data = $pager->getPageData();
	$links = $pager->getLinks();

//	$selectBox = $pager->getPerPageSelectBox();

	$tpl->assign( 'titles' , $titles );
	$tpl->assign( 'problem_num' , $problem_num );
	$tpl->assign( 'problems' , $page_data );
	$tpl->assign( 'links' , $links['all'] );	
 
}
$tpl->assign( 'isnotempty' , $isnotempty );
$tpl->display('manager_contest_detail.tpl');
}catch(Exception $e){
	echo $e->getMessage();
}
